Skip to content

Conversation

RayyanSeliya
Copy link
Contributor

Changes

  • 🐛 Fix confusing UX when using conflicting --image and --registry flags
  • 🧹 Implement 2-layer error system for image/registry validation
  • 🎁 Add clear guidance for resolving flag conflicts

/kind enhancement

Fixes #3065

Solution:

Implement a 2-layer error system:

  • Layer 1 (Technical): Return ErrConflictingImageAndRegistry from validation in pkg/functions/errors.go
  • Layer 2 (CLI): Catch the error in cmd/build.go and cmd/deploy.go and wrap with user-friendly guidance

Implementation Details:

  • Add validation logic in buildConfig.Validate() and deployConfig.Validate() methods
  • Use strings.HasPrefix() to check if image starts with registry (allows subnamespaces)
  • Maintain backward compatibility with existing test cases
  • Ensure error messages are consistent between build and deploy commands

Release Note

func build and func deploy commands now validate conflicting --image and --registry flags before starting the build process, providing clear error messages and actionable guidance instead of misleading build failures.

Copy link

knative-prow bot commented Oct 4, 2025

Hi @RayyanSeliya. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@knative-prow knative-prow bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 4, 2025
Copy link

codecov bot commented Oct 4, 2025

Codecov Report

❌ Patch coverage is 97.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 59.47%. Comparing base (c1b9a38) to head (0fb76e0).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
cmd/config_git_set.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3066      +/-   ##
==========================================
+ Coverage   58.66%   59.47%   +0.80%     
==========================================
  Files         133      133              
  Lines       17120    17153      +33     
==========================================
+ Hits        10044    10202     +158     
+ Misses       6146     5992     -154     
- Partials      930      959      +29     
Flag Coverage Δ
e2e-tests 40.55% <2.50%> (+1.25%) ⬆️
integration-tests 54.18% <97.50%> (+1.74%) ⬆️
unit-tests 46.48% <97.50%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@RayyanSeliya
Copy link
Contributor Author

I think i am missing some edge cases @gauron99 @lkingland please point out if any the test are still failing :(

@gauron99
Copy link
Contributor

gauron99 commented Oct 4, 2025

im gonna take a look tomorrow

@RayyanSeliya
Copy link
Contributor Author

Sure no worries !! Good night !

Copy link
Contributor

@gauron99 gauron99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we could simply check that -registry and --image are not given together at all? Image takes precedence now which is correct. But we want to avoid having the need to remove FUNC_REGISTRY or your registry in config file when trying to once specify --image for a different registry.
In other words --image should just take precedence and work even when FUNC_REGISTRY is specified BUT --image and --registry could just return an error saying "just choose one or the other" for simplicity?

Otherwise you would need to check both registries, determine what parts image contains and prepend (which I dont think works currently? check my other comment) and that would require a bit more work and consideration.

@lkingland WDYT?

cmd/build.go Outdated
// Skip validation if image has digest (@sha256:...) - digests are immutable overrides
if !strings.Contains(c.Image, "@sha256:") {
// Only validate if image has explicit registry (contains "/" or ":")
// Simple names like "myimage" are compatible - registry will be prepended
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are they really prepended?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❯ func build --image mine --registry quay.io/dfridric
Building function image
Still building
🙌 Function built: mine

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gauron99 u are right! The old validation was confusing , your test showed that --image override/takes precedence --registry, which wasn’t clear to users. We’ve fixed this by rejecting both flags when used together and showing a clear error message.

@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 5, 2025
@lkingland
Copy link
Member

I agree with @gauron99 on this one. Please simply check if the flags were both provided, and then raise an error that only one or the other should be provided, not both. 👍🏻

…between image and registry with different specified resgistry

Signed-off-by: RayyanSeliya <[email protected]>
…ding both flags together with clear error message

Signed-off-by: RayyanSeliya <[email protected]>
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 7, 2025
Copy link
Contributor

@gauron99 gauron99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, this already looks cleaner and simpler. I added a comment about one test

// resultant image member is updated but the registry member is not
// updated (subsequent builds will not be affected).
// Image flag sets the image directly when no registry is present
name: "image flag overrides",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this test we want to test exactly the case where image DOES override registry since registry is not being provided via flag but rather its already been given previously.

This test seems to to to cover the case when you

  1. func deploy --registry ...
    ... now f.registry exists in func.yaml and is not empty
  2. func deploy --image <different image>

we want this case to work -> override the image from registry thats been used from 1. with image from 2.
the func.yaml registry is NOT overriden and kept as is from 1. but the new image is used in deployment because --image was provided with different value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx for the clarification @gauron99 i have updated to included this test too ...

Signed-off-by: RayyanSeliya <[email protected]>
@RayyanSeliya RayyanSeliya requested a review from gauron99 October 7, 2025 11:57
Copy link
Member

@lkingland lkingland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/hold to make sure @gauron99 your OK too

@knative-prow knative-prow bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 8, 2025
@knative-prow knative-prow bot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Oct 8, 2025
Copy link
Contributor

@gauron99 gauron99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve
/unhold

@knative-prow knative-prow bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 8, 2025
Copy link

knative-prow bot commented Oct 8, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gauron99, lkingland, RayyanSeliya

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot merged commit d9efd36 into knative:main Oct 8, 2025
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/enhancement lgtm Indicates that a PR is ready to be merged. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

func build/deploy proceeds with build despite conflicting --image and --registry flags

4 participants